package com.zmn.oms.task.listener;

import com.zmn.common.utils.string.StringUtil;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.services.interfaces.enterpriseWeChat.EnterpriseWeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单延迟队列
* @author: LuJia
* @version: v1.0
* @since: 2020/5/18 14:50
**/
@AliyunMQListener(topic = "${spring.mq.topic.delay}")
@Component
@Slf4j
public class OrderDelayListenner {

    @Autowired
    private EnterpriseWeChatService enterpriseWeChatService;

    /**
     * 上门用户同步监听
     * @param message
     */
    @AliyunMQHandler(tags = OmsMqTagConsts.ZMN_TOPIC_OMS_VISIT_USER_SYNC_ORDER2ES)
    public void visitUserSync(String message) {

        if (StringUtil.isBlank(message)) {
            log.error("#mq#visitUserSync message is empty");
            return;
        }

        try {
            log.debug("#mq#visitUserSync# recive message:{}", message);
            enterpriseWeChatService.syncByVisitUserId(Long.parseLong(message));
        } catch (Exception e) {
            log.error("#mq#visitUserSync#{}", e.getMessage(), e);
        }
    }


}
